/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package parsers;



import java.io.File;
import java.net.URL;
import java.util.LinkedList;

import movie.Movie;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;



/**
 *
 * @author lopesdasilva
 */
public class LatestParser {
	public LinkedList<Movie> torrents = new LinkedList<Movie>();
	private static final boolean DEBUG = false;
	public LinkedList<Movie> parse(String URL){
		try {
			Document document = (Document) Jsoup.parse(new URL(URL), 200);
			//Document document = (Document) Jsoup.parse(filename, "UTF-8", "http://torrentbutler.eu/");	
			Elements movies = document.getElementsByClass("movie");
			for (Element movie : movies) {
				Elements a = movie.select("a");
				Elements c = a.select("span");
				Elements b = a.select("strong");

				String name=b.text();
				String year=c.last().text();
				String link="http://torrentbutler.eu"+a.attr("href");
				if (DEBUG)
				System.out.println("Name: "+name+"\nYear: "+year+"\nLink: "+link+"\n");
				torrents.add(new Movie(name,year,link));

			}

			

		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
		return torrents;


	}

}
